<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">角色分组</label>
                <div class="layui-input-block">
                    <select name="groupid">
                        <{foreach from=$groupList item=item}>
                        <option value="<{$item->gid}>"
                        <{if isset($data) and $item->gid eq $data->groupid}>selected<{/if}>><{$item->gname}>
                        </option>
                        <{/foreach}>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="username" <{if isset($data)}>value="<{$data->username}>" readonly
                    <{/if}>
                    lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">登陆密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" value="" placeholder="输入密码" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">当前状态</label>
                <div class="layui-input-block">
                    <input type="checkbox" <{if isset($data)}><{if $data->status eq
                    1}>checked="checked"<{/if}><{else}>checked="checked"<{/if}>
                    lay-filter="switch" name="status" lay-skin="switch" lay-text="正常使用|禁用">
                </div>
            </div>
            <{if isset($qrcodeurl)}>
            <div class="layui-form-item">
                <label class="layui-form-label">绑验证码</label>
                <div class="layui-input-block">
                    <input type="text" name="verifycode" value="" placeholder="扫码后产生的验证码" autocomplete="off"
                           class="layui-input"><br>
                    1. 用安装了google验证码软件的手机扫码如下二维码<br>
                    2. 在上面的输入框中输入产生的随机验证码<br>
                    <img src="<{$qrcodeurl}>"/>
                    <input type="hidden" name="google2fa_key" value="<{$google2fa_key}>">
                </div>
            </div>
            <{/if}>
            <div class="layui-form-item layui-hide">
                <input type="button" lay-submit lay-filter="form-submit" id="form-submit"
                       value="确认">
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'element'], function () {
        var $ = layui.$
            , form = layui.form
            , element = layui.element;

        form.render();
        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
        //监听提交
        form.on('submit(form-submit)', function (data) {
            var field = data.field; //获取提交的字段

            //提交 Ajax 成功后，关闭当前弹层并重载表格
            //$.ajax({});
            $.post('/<{$module}>/<{$controller}>/<{$action}>/id/<{if isset($data)}><{$data->id}><{/if}>?isajax=1&', field, function (res) {
                if (res.code == 0) {
                    //ok
                    layui.table.reload('table-page'); //重载表格
                    layer.close(parentIndex); //再执行关闭
                } else {
                    layer.msg(res.msg);
                }
            }, 'json')
        });
    })
</script>